package other;

/**
 * 用递归将n转成字符串 -32768-32767 5431
 */
public class NumToString {

  public static String numtoString(int num) {

    String sign = "-";

    if (num > 32368 || num < -32768) {
      throw new RuntimeException("数字的范围应在-32768-32767之间");
    }
    StringBuilder sb = new StringBuilder();

    if (num < 0) {
      sb.append(sign);
    }

    sb.append(toString(Math.abs(num)));

    return sb.toString();


  }


  private static String toString(int num) {

    StringBuilder sb = new StringBuilder();
    if (num / 10 == 0) {
      sb.append(num);
    } else {
      sb.append(toString(num / 10)).append(num % 10);
    }
    return sb.toString();
  }

  public static void main(String args[]) {
    System.out.println(numtoString(0));
  }

}
